import { enums } from 'src/assets/js/enums'
class MsgList {
  constructor () {
    // 状态
    this.statusOptions = [
      {
        label: '全部',
        value: 'all'
      },
      {
        label: '启用',
        value: 1
      },
      {
        label: '禁用',
        value: 0
      }
    ]
    // 状态红色按钮value
    this.redStopBtn = 0
    // 推送方式
    this.sendWayList = this._sendWay()
    // 消息概要, 触发条件枚举
    this.ruleList = this._setRuleList()
    // 动态生成触发条件文本
    this._setItemRule = ({ business, rule, type }) => {
      const ruleList = this.ruleList
      if (ruleList.has(business)) {
        const member = ruleList.get(business).setMes
        return member
      } else {
        console.log('枚举中不存在business;rule, 请及时更新!')
        return ''
      }
    }
    // 消息table
    this.columns = [
      {
        name: 'index',
        label: '序号',
        align: 'left',
        field: 'index'
      },
      { name: 'label', label: '消息类别', align: 'left', field: 'label' },
      { name: 'templateCode', label: '消息代码', align: 'left', field: 'templateCode' },
      { name: 'businessName', label: '消息概要', align: 'left', field: 'businessName' },
      { name: 'enable', label: '状态', align: 'left', field: 'enable' },
      {
        name: 'sendWayName',
        label: '推送方式',
        align: 'left',
        field: 'sendWayName'
      },
      { name: 'rule', label: '触发条件', align: 'left', field: 'rule' },
      {
        name: 'group',
        label: '接收角色',
        align: 'left',
        field: 'group'
      },
      {
        name: 'operations',
        field: 'operations',
        label: '操作',
        align: 'center'
      }
    ]
  }
  // 获取推送方式枚举
  _sendWay () {
    const member = Object.entries(enums.SEND_WAY).map(v => v[1]).reduce((arr, item) => {
      arr.push(
        {
          label: item.desc,
          value: item.value
        }
      )
      return arr
    }, [])
    console.log(member)
    return member
  }
  // 生成消息概要枚举
  _setRuleList () {
    const Role = new Map([
      ['PRODUCTION_WORK_AHEAD_SCHEDULE',
        {
          businessName: '作业进度超前提醒',
          rule: '作业进度超前大于@%',
          setMes: { desc: '作业进度超前大于', unit: '%', check: true }
        }
      ],
      ['PRODUCTION_WORK_BEHIND_SCHEDULE',
        {
          businessName: '作业进度落后提醒',
          rule: '作业进度落后大于',
          setMes: { desc: '作业进度落后大于', unit: '%', check: true }
        }
      ],
      ['PRODUCTION_PROCESS_ORDER_COMPLETED',
        {
          businessName: '加工工单完工',
          rule: '完工数量和计划数量相差大于 等于@',
          setMes: { desc: '即时触发', unit: '', isRule: true }
        }
      ],
      ['PRODUCTION_PROCESS_AUTO_START_FAIL',
        {
          businessName: '加工工单自动开工未成功',
          rule: '即时触发',
          setMes: { desc: '即时触发', unit: '', isRule: true }

        }
      ],
      ['PRODUCTION_PROCESS_ORDER_INSPECTION',
        {
          businessName: '加工工单报检',
          rule: '即时触发',
          setMes: { desc: '即时触发', unit: '', isRule: true }
        }
      ],
      ['CUTTER_STOCK_LOWER',
        {
          businessName: '刀具库存下限提醒',
          rule: '即时触发',
          setMes: { desc: '即时触发', unit: '', isRule: true }
        }
      ],
      ['MAINTENANCE_ORDER_GENERATE',
        {
          businessName: '保养工单生成提醒',
          rule: '即时触发',
          setMes: { desc: '即时触发', unit: '', isRule: true }
        }
      ],
      ['PRODUCTION_PROCESS_ORDER_BACK',
        {
          businessName: '加工工单打回',
          rule: '即时触发',
          setMes: { desc: '即时触发', unit: '', isRule: true }
        }
      ],
      ['TPM_OUTAGE_TIME',
        { businessName: '停机时长报警',
          rules: '停机时长超过@分钟',
          setMes: { desc: '停机时长超过', unit: '分钟', check: true }
        }
      ],
      ['TPM_OVERAGE_INFO',
        {
          businessName: '机床倍率报警',
          rule: '主轴倍率超过@%',
          setMes: { desc: '主轴倍率超过', unit: '%', check: true }
        }
      ],
      ['TPM_OVERAGE_INFO_LOWER',
        {
          businessName: '机床倍率信息提醒',
          rule: '主轴倍率超过@%',
          setMes: { desc: '主轴倍率低于', unit: '%', check: true }
        }
      ],
      ['PRODUCTION_CUTTER_LIFE_WARNING',
        {
          businessName: '刀具寿命预警',
          rule: '刀具剩余寿命小于@%',
          setMes: { desc: '刀具剩余寿命小于', unit: '%', check: true }
        }
      ],
      ['REPAIR_PENDING_TIMEOUT',
        {
          businessName: '维修单过期',
          rule: '维修工单待接单状态超过@分钟',
          setMes: { desc: ' 维修工单待接单状态超过', unit: '分钟', check: true }

        }
      ],
      ['MODULE_EXPIRATION_REMINDER',
        {
          businessName: '模块到期提醒',
          rule: '到期前@日时提醒',
          setMes: { desc: '到期前', unit: '日时提醒' }
        }
      ],
      ['BOX_DISCONNECTION',
        {
          businessName: '语祯盒子断开提醒',
          rule: ' 语祯盒子断开@小时',
          setMes: { desc: '语祯盒子断开', unit: '小时', check: true }
        }
      ],
      ['OVER_PRODUCE_WORK_ORDER_GENERATED',
        {
          businessName: '当班生成超产工单提醒',
          rule: '即时触发',
          setMes: { desc: '即时触发', unit: '', isRule: true }
        }
      ],
      ['REPAIR_ORDER_END',
        {
          businessName: '维修工单结束提醒',
          rule: '维修工单待接单状态超过@分钟',
          setMes: { desc: '即时触发', unit: '', isRule: true, check: true }
        }
      ],
      ['MAINTENANCE_ORDER_EXPIRE',
        {
          businessName: '保养工单过期提醒',
          rule: '即时触发',
          setMes: { desc: '即时触发', unit: '', isRule: true }
        }
      ],
      ['PRODUCTION_MOLD_LIFE_WARNING',
        {
          businessName: '模具寿命预警',
          rule: '模具剩余寿命小于@%',
          setMes: { desc: '模具剩余寿命小于', unit: '%', check: true }
        }
      ],
      ['PLC_PARAMETER_WARNING',
        {
          businessName: 'PLC参数预警',
          rule: '即时触发',
          setMes: { desc: '即时触发', unit: '', isRule: true }
        }
      ],
      ['MACHINE_CHANGEOVER',
        {
          businessName: '换线提醒',
          rule: '即时触发',
          setMes: { desc: '即时触发', unit: '', isRule: true }
        }
      ]
    ])
    return Role
  }
}
export default MsgList
